package com.dolphin.common.component.var.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author shida
 */

@Getter
public enum EsFieldTypeEnum {
    TEXT("text", ValueTypeEnum.STRING),
    KEYWORD("keyword", ValueTypeEnum.STRING),
    LONG("long", ValueTypeEnum.LONG),
    INTEGER("integer", ValueTypeEnum.INT),
    SHORT("short", ValueTypeEnum.INT),
    BYTE("byte", ValueTypeEnum.INT),
    DOUBLE("double", ValueTypeEnum.DOUBLE),
    FLOAT("float", ValueTypeEnum.FLOAT),
    DATE("date", ValueTypeEnum.DATE),
    BOOLEAN("boolean", ValueTypeEnum.BOOLEAN)
    ;

    private String fieldType;
    private ValueTypeEnum valueType;

    EsFieldTypeEnum(String fieldType, ValueTypeEnum valueType) {
        this.fieldType = fieldType;
        this.valueType = valueType;
    }

    public static String getByFieldType(String fieldType){
        if(StringUtils.isEmpty(fieldType)){
            return null;
        }

        for(EsFieldTypeEnum item : values()){
            if(Objects.equals(fieldType, item.fieldType)){
                return item.getValueType().name().toUpperCase();
            }
        }

        return null;
    }
}
